package org.example.memora.common.utils;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.data.message.ChatMessage;
public class ChatMessageUtils {

    public static String extractText(ChatMessage message) {
        if (message instanceof AiMessage ai) {
            return ai.text();
        } else if (message instanceof UserMessage user) {
            return user.hasSingleText()
                    ? user.singleText()
                    : "[unsupported: multiple contents]";
        } else {
            return "[unknown message type]";
        }
    }

    public static String extractRole(ChatMessage message) {
        if (message instanceof AiMessage) {
            return "AI";
        } else if (message instanceof UserMessage) {
            return "USER";
        } else {
            return "UNKNOWN";
        }
    }
}

